//
//  MY_LoginHttpApI.m
//  MiYuan_iOS
//
//  Created by zhangyongbing on 2018/5/9.
//  Copyright © 2018年 zhangyongbing. All rights reserved.
//

#import "MY_LoginHttpApI.h"

NSString *const MYURLPath_LoginGetsms = @"/oauth/sms";
NSString *const MYURLPath_Login = @"/oauth/app/token";

@implementation MY_LoginHttpApI

+ (void)myLoginGetSmsWithPhone:(NSString *)phonenumber
                      complationHandler:(OCJHttpResponseHander)handler {
    NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
    [mDic setObject:phonenumber forKey:@"phone"];
    
    [[OCJNetWorkCenter sharedCenter] ocj_POSTWithUrlPath:MYURLPath_LoginGetsms parameters:mDic andLodingType:OCJHttpLoadingTypeNone completionHandler:^(OCJBaseResponceModel *responseModel) {
//        OCJGlobalHomeDataModel *model = [[OCJGlobalHomeDataModel alloc] initOCJSubResponceModelSetValuesWithBaseResponceModel:responseModel];
        handler(responseModel);
        
        if (![responseModel.ocjStr_code isEqualToString:@"0"]) {
            [SGInfoAlert showInfo:responseModel.ocjStr_message
                          bgColor:[[UIColor blackColor] CGColor]
                           inView:[[UIApplication sharedApplication] keyWindow]
                         vertical:0.7];
        }
    }];
}

+(void)myLoginServicesWithPhone:(NSString *)phonenumber
                           Code:(NSString *)code
              complationHandler:(OCJHttpResponseHander)handler
{
    NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
    [mDic setObject:phonenumber forKey:@"phone"];
    [mDic setObject:code forKey:@"code"];
    
    [[OCJNetWorkCenter sharedCenter] ocj_POSTWithUrlPath:MYURLPath_Login parameters:mDic andLodingType:OCJHttpLoadingTypeNone completionHandler:^(OCJBaseResponceModel *responseModel) {
        handler(responseModel);
        
        if (![responseModel.ocjStr_code isEqualToString:@"0"]) {
            [SGInfoAlert showInfo:responseModel.ocjStr_message
                          bgColor:[[UIColor blackColor] CGColor]
                           inView:[[UIApplication sharedApplication] keyWindow]
                         vertical:0.7];
        }
        else
        {
            NSString    *strtoken = [responseModel.ocjDic_data objectForKey:@"access_token"];
            [[NSUserDefaults standardUserDefaults] setObject:strtoken forKey:@"access_token"];
            [[NSUserDefaults standardUserDefaults] synchronize];

        }
    }];
}

@end
